package com.code.day20;

import java.io.FileInputStream;
import java.io.IOException;

public class Demo04FileInputStream {
    public static void main(String[] args) throws IOException {
        /**
         * int read(byte[] b) 一次读多个字节,返回的是读取到的字节个数
         */

        FileInputStream fileInputStream = new FileInputStream("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo1.txt");
        byte[] bytes = new byte[3];
        int len = 0; //接收的字节个数
        while ((len = fileInputStream.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, len));
//            System.out.println(new String(bytes)); // 如果直接转为字符串 则可能会导致有一个数据被覆盖 而另一个没被覆盖
        }

    }
}
